package cn.tedu.egmvc8.controller;

import cn.tedu.egmvc8.mapper.NoticeMapper;
import cn.tedu.egmvc8.pojo.dto.NoticeAddParam;
import cn.tedu.egmvc8.pojo.dto.NoticeAddQuery;
import cn.tedu.egmvc8.pojo.entity.Notice;
import cn.tedu.egmvc8.pojo.vo.NoticeDetailInfoVO;
import cn.tedu.egmvc8.pojo.vo.NoticeListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;
import java.util.List;

@Controller
public class NoticeController {
    @Autowired
    NoticeMapper noticeMapper;
    @PostMapping("/v1/notice/add")
    @ResponseBody
    public String add(NoticeAddParam noticeAddParam) {
        System.out.println("noticeAddParam = " + noticeAddParam);
        Notice notice = new Notice();
        BeanUtils.copyProperties(noticeAddParam, notice);
        notice.setUserId(100L);
        notice.setCreateTime(LocalDateTime.now());
        notice.setUpdateTime(LocalDateTime.now());
        noticeMapper.insert(notice);
        return "新增资讯成功";
    }

    @GetMapping("/v1/notice/detail")
    @ResponseBody
    public NoticeDetailInfoVO getNoticeDetail(long id){

        NoticeDetailInfoVO noticeDetail =noticeMapper.getNoticeDetail(id);

        return noticeDetail;
    }
}
